package com.david.rabbitmq.ttl.controller;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

/**
 * @author David
 * @version V1.0
 * @Package com.david.rabbitmq.ttl.controller
 * @date 2021/7/18 14:55
 */
@RestController
public class MessageController {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    /**
     * 正常业务
     * @return
     */
    @RequestMapping("/go")
    public String distributeGo() {
        rabbitTemplate.convertAndSend("ex.go", "go", "送单到石景山x小区，请在10秒内接受任务");
        return "任务已经下发，等待送单。。。";
    }

    /**
     * 查看死信消息
     * @return
     */
    @RequestMapping("/notgo")
    public String getAccumulatedTask() {
        String notGo = (String) rabbitTemplate.receiveAndConvert("q.go.dlx");
        return notGo;
    }
}
